package dl.jf.dao.impl.admin;

import java.util.ArrayList;


import dl.jf.common.constants.Constants;
import dl.jf.common.model.LabelValue;
import dl.jf.common.model.MCode;
import dl.jf.common.model.MUser;
import dl.jf.dao.idao.ICommonDao;
import dl.jf.dao.idao.admin.IAdminMemberDao;
import dl.jf.dao.impl.BaseDaoImpl;

public class AdminMemberDaoImpl extends BaseDaoImpl implements IAdminMemberDao {

	@SuppressWarnings("unchecked")
	@Override
	public ArrayList<LabelValue> getRoleLabelListById(Integer roleId) throws Exception {
		return (ArrayList<LabelValue>) getSqlMapClientTemplate().queryForList(
				"adminMemberSQL.getRoleLabelListById", roleId);
	}
	
	@Override
	public MUser getUserListByUserId(String userId) throws Exception{
		return (MUser)getSqlMapClientTemplate().queryForObject(
				"adminMemberSQL.getUserListByUserId", userId);
	}

	@SuppressWarnings("unchecked")
	@Override
	public ArrayList<MUser> getUserListByUser(MUser user) throws Exception{
		return (ArrayList<MUser>)getSqlMapClientTemplate().queryForList(
				"adminMemberSQL.getUserListByUser", user);
	}
	
	@Override
	public Integer getUserListByUserTotal(MUser user) throws Exception{
		return (Integer)getSqlMapClientTemplate().queryForObject(
				"adminMemberSQL.getUserListByUserTotal", user);
	}
	
	@Override
	public String insertUser(MUser user) throws Exception {
		return (String)getSqlMapClientTemplate().insert("adminMemberSQL.insertUser", user);
	}
//	@Override
//	public String getGenerateCode(int code, int len, String prefix) throws Exception {
//		Integer no = (Integer) getSqlMapClientTemplate().queryForObject(
//				"commonSQL.getGenerateCode", code);
//
//		if ((++no).toString().length() > len) {
//			no = 1;
//		}
//		MCode model = new MCode();
//		model.setCode(code);
//		model.setContent(no.toString());
//		getSqlMapClientTemplate().update("commonSQL.updateGenerateCode", model);
//		return prefix + String.format("%0" + Integer.toString(len) + "d", no);
//	}

	@Override
	public int updateUserByUserId(MUser user) throws Exception {
		return getSqlMapClientTemplate().update("adminMemberSQL.updateUserByUserId", user);
	}

	@Override
	public int deleteUserByUserId(String userId) throws Exception {
		return getSqlMapClientTemplate().delete("adminMemberSQL.deleteUserByUserId", userId);
	}
}
